Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 24, 2025

This PR completes the migration from traditional ASP.NET Core controllers to modern Minimal APIs, implementing .NET 9 best practices throughout the NLWebNet library.

Changes Made

🔄 Minimal API Migration

  • Converted all endpoints to use TypedResults instead of Results for improved type safety
  • Added strongly typed return signatures for better compile-time checking
  • Implemented .NET 9 best practices for parameter binding and dependency injection

🗑️ Legacy Code Removal

  • Removed AskController.cs and McpController.cs - controllers completely eliminated
  • Deleted Controllers directory - no longer needed
  • Removed controller registrations from ServiceCollectionExtensions.cs
  • Eliminated legacy MapNLWebNetControllers() method from extension methods

🧪 Test Updates

  • Removed controller test files (AskControllerTests.cs, McpControllerTests.cs)
  • Maintained endpoint test coverage - all functionality preserved (35/35 tests passing)
  • Reduced test count from 50 to 35 due to controller test removal

📚 Documentation Updates

  • Updated development guide to reflect Minimal APIs exclusively
  • Removed controller references from API documentation
  • Updated project structure diagrams and examples
  • Modernized code samples to use service patterns instead of controllers

Benefits

  • Better Type Safety: TypedResults provide compile-time type checking
  • Improved Performance: Minimal APIs have lower overhead than controllers
  • Modern .NET 9 Patterns: Full adoption of current best practices
  • Cleaner Architecture: Simplified dependency injection and routing
  • Reduced Complexity: Eliminated dual controller/endpoint maintenance

Before/After Comparison

Before (Controllers)

[ApiController]
[Route("ask")]
public class AskController : ControllerBase
{
    public async Task<IActionResult> ProcessQuery([FromBody] NLWebRequest request)
    {
        var response = await _nlWebService.ProcessRequestAsync(request);
        return Ok(response);
    }
}

After (Minimal APIs with TypedResults)

private static async Task<Results<Ok<NLWebResponse>, BadRequest<ProblemDetails>, StatusCodeHttpResult>> ProcessQueryAsync(
    [FromBody] NLWebRequest request,
    INLWebService nlWebService, ILoggerFactory loggerFactory,
    CancellationToken cancellationToken = default)
{
    var response = await nlWebService.ProcessRequestAsync(request, cancellationToken);
    return TypedResults.Ok(response);
}

Testing

  • ✅ All builds successful (Debug/Release)
  • ✅ All tests passing (35/35)
  • ✅ Endpoint functionality preserved
  • ✅ API contract unchanged for consumers

Fixes #26.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] ⚙️ Convert Controllers in NLWebNet library to Minimal APIs ⚙️ Convert Controllers to Minimal APIs with .NET 9 TypedResults Jun 24, 2025
Copilot AI requested a review from jongalloway June 24, 2025 18:36
Copilot finished work on behalf of jongalloway June 24, 2025 18:36
@jongalloway jongalloway marked this pull request as ready for review June 24, 2025 18:38
@jongalloway jongalloway merged commit 5c8f175 into main Jun 24, 2025
16 checks passed
@jongalloway jongalloway deleted the copilot/fix-26 branch July 1, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚙️ Convert Controllers in NLWebNet library to Minimal APIs

2 participants